---
import MyMain from "./index.astro";
export async function getStaticPaths() {
  const allPosts = await Astro.glob("../posts/*.md");

  const uniqueTags = [
    ...new Set(allPosts.map(post => post.frontmatter.tags).flat()),
  ];

  return uniqueTags.map(tag => {
    const filteredPosts = allPosts.filter(post =>
      post.frontmatter.tags.includes(tag)
    );
    return {
      params: { tag },
      props: { posts: filteredPosts },
    };
  });
}

const { tag } = Astro.params;
const { posts } = Astro.props;
export const prerender = true;
---

<MyMain posts={posts} />
